package com.antu.first.service.impl;

import com.antu.first.bean.Room;
import com.antu.first.bean.RoomType;
import com.antu.first.dao.HotelDao;
import com.antu.first.dao.RoomDao;
import com.antu.first.dao.RoomTypeDao;
import com.antu.first.service.RoomService;
import com.antu.first.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/4.
 */
@Service("roomService")
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomDao roomlDao;
    @Autowired
    private RoomTypeDao roomTypeDao;
    List<Room>list=new ArrayList();
    boolean flag;
    Map<String, Object> map;
    @Override
    public Map<String, Object> selectRoomsByHotelIdAndRoomTypeId(Room room,Integer currentPage,Integer pageSize) {
        map=new HashMap<String,Object>();
        int i=roomlDao.selectRoomsByHotelIdAndRoomTypeIdCount(room);//总条数
        PageBean pageBean=new PageBean(currentPage,i,pageSize);//计算
        List<Room> pageList=roomlDao.selectRoomsByHotelIdAndRoomTypeIdPaging(room,pageBean);
        pageBean.setList(pageList);
        List<RoomType>roomTypeList=roomTypeDao.queryRoomTypeByHid(room.getrId());
        map.put("roomTypes",roomTypeList);
        map.put("pageBean",pageBean);
        map.put("room",room);//传入的查询条件用于回显
        return map;
    }
    @Override
    public Map<String, Object> updateRoomInfoByHoteId(Room room) {
        map=new HashMap<String,Object>();
        if(room.getrId()!=0&&room.getHotel()!=null&&room.getrDesc()!=null&&room.getrName()!=null&&room.getrOriginalPrice()>=0.00&&room.getrPresentPrice()>=0.00
                &&room.getrRepertory()>=0&&room.getrType()!=null){
            int i=roomlDao.updateRoomInfoByHoteId(room);
            if (i>0){
                map.put("success",true);
            }else {
                map.put("errMsg","操作失败,请核对信息是否完整");
                map.put("success",false);
            }
        }else{
            map.put("errMsg","操作失败,请核对信息是否完整");
            map.put("success",false);
        }
        return map;
    }

    @Override
    public Map<String, Object> addRoomByHotelId(Room room) {
        map=new HashMap<String,Object>();
        int i=roomlDao.insertRoom(room);
        if (i>0){
            map.put("success",true);
        }else {
            map.put("errMsg","新增操作失败,请核对信息是否完整");
            map.put("success",false);
        }
        return map;
    }

    @Override
    public Map<String, Object> deleteRoomByIdHotelId(Room room) {
        map=new HashMap<String,Object>();
        int i=roomlDao.deleteRoomByIdHotelId(room);
        if (i>0){
            map.put("success",true);
        }else {
            map.put("errMsg","删除操作失败,请核对信息是否完整");
            map.put("success",false);
        }
        return map;
    }
}
